package com.wanmait.translate.dto;

import com.wanmait.translate.dto.audit.AuditContentInterface;

import java.util.*;

/*
 * @Author huweibin
 * @Description 用于表述日期和审核的对应关系
 * @Date 21:08 2020/11/23
 **/
public class ListToDo {
    //日期：审核内容
    private Map<String,List<TypeContent>> map=new HashMap<>();

    public Map<String, List<TypeContent>> getMap() {
        return map;
    }

    //获得根据状态排序的结果
    public TreeMap<String,List<ReturnState>> getCountSateSortResult(){
        //TreeMap保证顺序
        TreeMap<String,List<ReturnState>> result=new TreeMap<>();
         //循环所有天
        for (Map.Entry<String, List<TypeContent>> entry : map.entrySet()) {
            String day = entry.getKey();
            List<TypeContent> values = entry.getValue();
            //循环所有类别
            for (TypeContent value : values) {
                //循环所有状态
                for (Object state : value.getStates()) {
                    if(result.get(day)==null){
                        result.put(day, new ArrayList<>());
                    }
                    result.get(day).add(new ReturnState(value,(TypeContent.State)state));
                }
                //一天中状态排序
                result.get(day).sort(Comparator.comparingInt(ReturnState::getTypeId));
            }
        }
        return result;
    }

    //获得根据时间排序的结果
    public TreeMap<String,List<AuditContentInterface>> getListTimeSortResult(){
        //TreeMap保证顺序
        TreeMap<String,List<AuditContentInterface>> result=new TreeMap<>();
        //循环所有天(一般只有一天)
        for (Map.Entry<String, List<TypeContent>> entry : map.entrySet()) {
            List<AuditContentInterface> resList = new ArrayList<>();
            //循环每一个TypeContent的list合并到一起
            entry.getValue().forEach((list)->{
                resList.addAll( list.getList());
            });
            resList.sort(Comparator.comparing(AuditContentInterface::getInputDate));
            result.put(entry.getKey(),resList);
        }
        return result;
    }
    //获得指定日期所有审核情况
    public List<TypeContent> getTypeContent(String day) {
        return map.get(day);
    }

    public void addTypeContent(String day,TypeContent typeContent){
        List<TypeContent> typeContents = this.map.get(day);
        if (typeContents==null){
            map.put(day,new ArrayList<TypeContent>());
            typeContents=map.get(day);
        }
        typeContents.add(typeContent);
    }


    @Override
    public String toString() {
        return "ListToDo{" +
                "map=" + map +
                '}';
    }

    //用于返回的封装
    public  class ReturnState{
        private  String type;
        //类别的中文名
        private  String typeName;
        //类别的ID
        private  Integer typeId;
        //当前状态名
        private String name;
        //状态的Id(对应枚举类的索引)
        private Integer stateId;
        //此状态的数量
        private  Integer count;
        //对应的数据
        private List list;

        public ReturnState(TypeContent typeContent, TypeContent.State state) {
            this.type = typeContent.getType();
            this.typeName = typeContent.getTypeName();
            this.typeId = typeContent.getTypeId();
            this.name = state.getName();
            this.stateId = state.getStateId();
            this.count = state.getCount();
        }


        public ReturnState() {
        }

        @Override
        public String toString() {
            return "returnState{" +
                    "type='" + type + '\'' +
                    ", typeName='" + typeName + '\'' +
                    ", typeId=" + typeId +
                    ", name='" + name + '\'' +
                    ", stateId=" + stateId +
                    ", count=" + count +
                    ", list=" + list +
                    '}';
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public String getTypeName() {
            return typeName;
        }

        public void setTypeName(String typeName) {
            this.typeName = typeName;
        }

        public Integer getTypeId() {
            return typeId;
        }

        public void setTypeId(Integer typeId) {
            this.typeId = typeId;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getStateId() {
            return stateId;
        }

        public void setStateId(Integer stateId) {
            this.stateId = stateId;
        }

        public Integer getCount() {
            return count;
        }

        public void setCount(Integer count) {
            this.count = count;
        }

        public List getList() {
            return list;
        }

        public void setList(List list) {
            this.list = list;
        }
    }
}
